package handlers

import (
	"car-trade-sys/model"
	"github.com/gin-gonic/gin"
)

func UList(c *gin.Context) {
	uid := c.Query("uid")
	/*
		SELECT
		  *
		FROM
		  roles
		  LEFT JOIN user_roles ON user_roles.rid = roles.id
		WHERE
		  user_roles.uid = 1
	*/
	var role []model.Role
	model.DB.Table("roles").
		Joins("LEFT JOIN user_roles ON user_roles.rid = roles.id").
		Where(" user_roles.uid = ?", uid).
		Debug().
		Find(&role)
	c.JSON(200, gin.H{
		"code": 200,
		"data": role,
		"msg":  "success",
	})
}
